﻿using System;
using JTLeigh.Commerce.Spencer.Core.Common.Exceptions;
using JTLeigh.Commerce.Spencer.Core.Testing;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace JTLeigh.Commerce.Spencer.Core.Common.UnitTests.Exceptions
{

	/// <summary>
	/// Unit tests for the <see cref="AssertionFailedException"/> class.
	/// </summary>
	[TestClass]
	public class AssertionFailedExceptionFixture
	{

		#region Methods

		#region Constructors

		/// <summary>
		/// Ensures the default constructor sets the message to <see cref="AssertionFailedException.DefaultMessage"/>
		/// and the inner exception to <see langword="null"/>.
		/// </summary>
		[TestMethod]
		public void TestDefaultConstructor()
		{
			AssertionFailedException exception;

			exception = new AssertionFailedException();
			Assert.AreEqual(AssertionFailedException.DefaultMessage, exception.Message);
			Assert.IsNull(exception.InnerException);
		}

		/// <summary>
		/// Ensures the message constructor sets the message to the specified message and the inner
		/// exception to <see langword="null"/>.
		/// </summary>
		[TestMethod]
		public void TestMessageConstructor()
		{
			AssertionFailedException exception;

			exception = new AssertionFailedException("testMessage");
			Assert.AreEqual("testMessage", exception.Message);
			Assert.IsNull(exception.InnerException);
		}

		/// <summary>
		/// Ensures the message/inner exception constructor sets the message to the specified 
		/// message and the inner exception to the specified exception.
		/// </summary>
		[TestMethod]
		public void TestMessageInnerExceptionConstructor()
		{
			InvalidOperationException innerException;
			AssertionFailedException exception;

			innerException = new InvalidOperationException("testMessage");
			exception = new AssertionFailedException("testMessage", innerException);
			Assert.AreEqual("testMessage", exception.Message);
			Assert.AreSame(innerException, exception.InnerException);
		}

		#endregion // Constructors

		#region Serialization/Deserialization

		/// <summary>
		/// Ensures <see cref="AssertionFailedException"/> objects can be serialized and 
		/// deserialized with no loss of data.
		/// </summary>
		[TestMethod]
		public void TestSerializationDeserialization()
		{
			InvalidOperationException innerException;
			AssertionFailedException source;
			AssertionFailedException resulting;

			innerException = new InvalidOperationException("testMessage");
			source = new AssertionFailedException("testMessage", innerException);
			resulting = SerializationTestTools.BinarySerializeDeserialize<AssertionFailedException>(source);
			Assert.AreEqual(source.Message, resulting.Message);
			Assert.AreEqual(source.InnerException.ToString(), resulting.InnerException.ToString());
		}

		#endregion // Serialization/Deserialization

		#endregion // Methods

	}

}
